
import { CustomSkillManage } from "../全局对象/CustomSkillManage";
import { DamageChangeManage } from "../全局对象/DamageManage";
import { FreshBoss } from "../全局对象/FreshBoss";
import { FreshMon } from "../全局对象/FreshMon";
import { ItemMangae } from "../全局对象/ItemManage";
import { SkillManage } from "../全局对象/SkillManage";
import { SlaveManage } from "../全局对象/slaveManage";
import { SpecialMonManage } from "../全局对象/SpecialMonManage";
import { MonGenSet } from "../配置/刷怪";
import { MonGenBossSet } from "../配置/刷新BOSS";
import { SpecialMonSkillSet } from "../配置/特殊怪物";
import { customSkillSet } from "../配置/自定义技能";
import { readStrFromFile } from "../utils/mirUtil";
import { produceChanceList } from "../配置/鉴定系统/鉴定系统";
import { ItemLevelName } from "../配置/装备等级";
import { deleteLog, LogType, saveLog } from "../utils/LogUtil";
import { MonItemManage } from "../全局对象/MonItemManage";

//刷怪管理
let freshMon: FreshMon;
//刷新BOSS管理
let freshBoss: FreshBoss;
//自定义技能管理
let customSkill: CustomSkillManage;

//特殊怪物管理
let specialMonManage: SpecialMonManage;

//伤害管理
let damageManage: DamageChangeManage;

//物品等级管理
let itemMangae: ItemMangae;

//普通技能管理
let skillManage: SkillManage;

//宝宝管理
let slaveManage: SlaveManage;

//刷怪管理
let monItemManage: MonItemManage;

//初始化
export function globalInit(isReload) {
    initSkillMap();



    customSkill = new CustomSkillManage(customSkillSet);
    specialMonManage = new SpecialMonManage(SpecialMonSkillSet)
    damageManage = new DamageChangeManage();
    freshMon = new FreshMon(MonGenSet);

    freshBoss = new FreshBoss(MonGenBossSet);

    itemMangae = new ItemMangae();
    slaveManage = new SlaveManage();
    skillManage = new SkillManage();
    monItemManage = new MonItemManage();


    // console.log(JSON.stringify(produceChanceList(300, ItemLevelName.length)))
    // console.log(GameLib.TickCount);
    // let list=[1,2,6,9,10,20,25]
    // console.log(getRandomList(list));

    // console.log(GameLib.TickCount);
}

//释放的时候
export function globalFinal() {
    freshBoss.save();
}

export function getFreshMon(): FreshMon {
    return freshMon;
}
export function getFreshBoss(): FreshBoss {
    return freshBoss;
}

export function getCustomSkillManage(): CustomSkillManage {
    return customSkill;
}

export function getSpecialMonManage(): SpecialMonManage {
    return specialMonManage;
}
export function getDamageChangeManage(): DamageChangeManage {
    return damageManage;
}

export function getItemMangae(): ItemMangae {
    return itemMangae;
}
export function getSkillManage(): SkillManage {
    return skillManage;
}
export function getSlaveManage(): SlaveManage {
    return slaveManage;
}
export function getMonItemManage(): MonItemManage {
    return monItemManage;
}




let skillIdMap = null;
let skillNameMap = null;
//初始化技能的映射
export function initSkillMap() {
    skillIdMap = {};
    skillNameMap = {};

    // console.log("111111111111")

    //读取导出的技能数据库json文件
    let json = readStrFromFile('配置/Magic.txt');
    // console.log(json)
    let data = JSON.parse(json);

    if (data && data.length > 0) {
        for (let i = 0; i < data.length; i++) {
            let item = data[i];
            skillIdMap[item.Name] = item.MagID;
            skillNameMap[item.MagID] = item.Name;
        }
    }


    readCustomSkill()

    // TestQueue()

}

//读取导出的自定义技能json文件
function readCustomSkill() {
    let json = readStrFromFile('配置/自定义技能.json');
    // console.log(json)
    let data = JSON.parse(json);
    if (data && data.Skills) {
        const { Dirs } = data.Skills;
        readCustomDirs(Dirs)
    }
}

function readCustomDirs(data): void {
    if (!data || data.length == 0) {
        return;
    }
    for (let i = 0; i < data.length; i++) {
        let item = data[i];
        const { Skills, Dirs } = item;
        for (let j = 0; j < Skills.length; j++) {
            let skillItem = Skills[j];
            skillIdMap[skillItem.Name] = skillItem.ID;
            skillNameMap[skillItem.ID] = skillItem.Name;
        }
        readCustomDirs(Dirs)

    }
}

export function getSkillId(skillName: string) {
    return skillIdMap[skillName] || 0;
}

export function getSkillName(skillId: number) {
    return skillNameMap[skillId] || '';
}

